<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件中的数据存放问题</title>
</head>
<body>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <template id="cpn">
        <div>
            <h2>当前计数：{{counter}}</h2>
            <button @click="add">+</button>
            <button @click="sub">-</button>
        </div>
    </template>
</body>
    <script src="../js/vue.js"></script>
    <script>
        Vue.component('cpn',{
            template: '#cpn',
            data (){
                return {
                    counter: 0
                }
            },
            methods: {
                add (){
                    this.counter++;
                },
                sub (){
                    this.counter--;
                }
            }
        })

        const app = new Vue({
            el: '#app',
            data: {
                message: 'hello',
            },
            methods: {

            },
            components: {

            }
        })
    </script>
</html>